home *** CD-ROM | disk | FTP | other *** search
- /* AuditFileDialog.c */
- /*
- * AuditFileDialog.c
- * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
- * Programmed by Martin Minow,
- * Internet: minow@apple.com
- * AppleLink: MINOW
- * Version of January 22, 1993
- *
- * File Dialog for Audit display. This replaces the SFPutFile dialog, adding a
- * TextEdit field for the Audit Selector and a checkbox for "initially enabled."
- * See Inside Mac Files (3-21) for details.
- *
- * Edit History
- * 93.01.14 MM First public release
- * 93.07.09 MM Reformatted for 80-column page. Added a TextEdit field for
- * the number of lines to remember in the display log.
- */
- #include "DisplayAudit.h"
- #include <StandardFile.h>
-
- /*
- * Standard File dialog items. This follows the layout of the old Standard File
- * (-3999) DITL. Our private items are at the end.
- */
- enum {
- kSFSaveButton = 1,
- kSFCancelButton,
- kSFSaveAsStaticText,
- kSFVolumeUser,
- kSFEjectButton,
- kSFDriveButton,
- kSFFileNameTextEdit,
- kSFFileListUser,
- kSFItemSelectorTextEdit,
- kSFItemSelectorStaticText,
- kSFItemAuditRecordsTextEdit,
- kSFItemAuditRecordsStaticText,
- kSFItemLogLinesTextEdit,
- kSFItemLogLinesStaticText,
- kSFItemEnabledCheckBox,
- kSFItemFontPopupMenu,
- kSFItemFontSizePopupMenu
- };
- enum {
- kFirstTime = -1 /* the first time our hook it's passed a -1 */
- };
-
- static pascal short PutDialogFilter(
- short itemHit,
- DialogPtr theDialog
- );
-
- /*
- * AuditFileDialog updates the global parameter resource.
- */
- void
- AuditFileDialog(
- short dialogID,
- ConstStr255Param promptString,
- ConstStr255Param originalName,
- SFReply *reply
- )
- {
- Point where;
- DialogTHndl dialogHdl;
- Rect box;
-
- /*
- * Center the dialog
- */
- dialogHdl = (DialogTHndl) GetResource('DLOG', dialogID);
- if (dialogHdl == NULL) { /* No resource! */
- Failure(resNotFound, kErrCreateAuditRecord);
- SetPt(&where, 80, 80);
- }
- else {
- box = (**dialogHdl).boundsRect; /* Dialog shape */
- ReleaseResource((Handle) dialogHdl);
- where.h =
- (width(qd.screenBits.bounds) - width(box)) / 2;
- where.v =
- ((height(qd.screenBits.bounds) - GetMBarHeight()) / 3)
- + GetMBarHeight()
- - (height(box) / 3);
- }
- SFPPutFile(
- where,
- promptString,
- originalName,
- (DlgHookProcPtr) PutDialogFilter, /* Dialog item filter */
- reply,
- dialogID,
- NULL /* No Modal Dialog Filter */
- );
- gParameterUpdateNeeded = TRUE;
- }
-
- static pascal short
- PutDialogFilter(
- short itemHit,
- DialogPtr theDialog
- )
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
- short i;
- short nMenuItems;
- short selectedSize;
- short parmFontNum;
- Str255 work;
- Str15 fontSizeText;
- #define DIALOG (* ((DialogPeek) theDialog))
-
- switch (itemHit) {
- case kFirstTime:
- /*
- * Copy the audit selector from the global storage to the dialog item.
- */
- work[0] = 4;
- BlockMove(&PARM.auditIdent, &work[1], 4);
- for (i = 1; i <= 4; i++) {
- if (work[i] < ' ') {
- work[0] = i - 1;
- break;
- }
- }
- GetDItem(
- theDialog,
- kSFItemSelectorTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- SetIText(itemHandle, work);
- /*
- * Set the log records field.
- */
- GetDItem(
- theDialog,
- kSFItemAuditRecordsTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- NumToString(PARM.auditRecords, work);
- SetIText(itemHandle, work);
- /*
- * Set the log display lines field.
- */
- GetDItem(
- theDialog,
- kSFItemLogLinesTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- NumToString(PARM.logDisplayLines, work);
- SetIText(itemHandle, work);
- /*
- * Set the checkbox status.
- */
- GetDItem(
- theDialog,
- kSFItemEnabledCheckBox,
- &itemType,
- &itemHandle,
- &itemRect
- );
- SetCtlValue((ControlHandle) itemHandle, PARM.enableAudit);
- /*
- * Set the font name popup menu
- */
- nMenuItems = CountMItems(gFontMenu);
- for (i = 1; i <= nMenuItems; i++) {
- GetItem(gFontMenu, i, work);
- if (EqualString(work, PARM.fontName, FALSE, FALSE))
- break;
- }
- if (i <= nMenuItems) {
- GetDItem(
- theDialog,
- kSFItemFontPopupMenu,
- &itemType,
- &itemHandle,
- &itemRect
- );
- SetCtlValue((ControlHandle) itemHandle, i);
- }
- /*
- * Set the font size popup menu
- */
- GetFNum(PARM.fontName, &parmFontNum);
- nMenuItems = CountMItems(gFontSizeMenu);
- NumToString(PARM.fontSize, fontSizeText);
- selectedSize = 0;
- for (i = 1; i <= nMenuItems; i++) {
- GetItem(gFontSizeMenu, i, work);
- if (EqualString(work, fontSizeText, FALSE, FALSE))
- selectedSize = i;
- }
- if (selectedSize != 0) {
- GetDItem(
- theDialog,
- kSFItemFontSizePopupMenu,
- &itemType,
- &itemHandle,
- &itemRect
- );
- SetCtlValue((ControlHandle) itemHandle, selectedSize);
- }
- break;
- case kSFItemEnabledCheckBox:
- GetDItem(
- theDialog,
- kSFItemEnabledCheckBox,
- &itemType,
- &itemHandle,
- &itemRect
- );
- SetCtlValue(
- (ControlHandle) itemHandle,
- 1 - GetCtlValue((ControlHandle) itemHandle)
- );
- break;
- case kSFSaveButton:
- case kSFCancelButton:
- /*
- * Exit: get the audit selector, even if the user hit the "Cancel"
- * button. SFPPutFile will still return reply->good == FALSE if the
- * file isn't to be created.
- */
- GetDItem(
- theDialog,
- kSFItemSelectorTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- GetIText(itemHandle, work);
- PARM.auditIdent = 0;
- for (i = work[0] + 1; i <= 4; i++)
- work[i] = 0;
- if (work[0] != 4)
- work[0] = 4;
- BlockMove(&work[1], &PARM.auditIdent, 4);
- /*
- * Get the number of log records.
- */
- GetDItem(
- theDialog,
- kSFItemLogLinesTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- GetIText(itemHandle, work);
- StringToNum(work, &PARM.auditRecords);
- /*
- * Get the number of lines.
- */
- GetDItem(
- theDialog,
- kSFItemAuditRecordsTextEdit,
- &itemType,
- &itemHandle,
- &itemRect
- );
- GetIText(itemHandle, work);
- StringToNum(work, &PARM.logDisplayLines);
- /*
- * Get the checkbox status.
- */
- GetDItem(
- theDialog,
- kSFItemEnabledCheckBox,
- &itemType,
- &itemHandle,
- &itemRect
- );
- PARM.enableAudit = GetCtlValue((ControlHandle) itemHandle);
- /*
- * Get the font name
- */
- GetDItem(
- theDialog,
- kSFItemFontPopupMenu,
- &itemType,
- &itemHandle,
- &itemRect
- );
- i = GetCtlValue((ControlHandle) itemHandle);
- GetItem(gFontMenu, i, PARM.fontName);
- /*
- * Get the font size
- */
- GetDItem(
- theDialog,
- kSFItemFontSizePopupMenu,
- &itemType,
- &itemHandle,
- &itemRect
- );
- i = GetCtlValue((ControlHandle) itemHandle);
- GetItem(gFontSizeMenu, i, work);
- StringToNum(work, &PARM.fontSize);
- }
- return (itemHit);
- }
-
-